package awesome.cpu.structure;

import awesome.cpu.utils.Mode;

public class ALUOut extends SequentialComponent {
	
	private static boolean outputDebug = false;
	
	public final static int KEY_ALU_RESULT_HI = 1;
	private int mALUResultHi;
	public final static int KEY_ALU_RESULT_LO = 2;
	private int mALUResultLo;
	
	public final static int KEY_ALU_OUT_HI = 3;
	private int mALUOutHi;
	public final static int KEY_ALU_OUT_LO = 4;
	private int mALUOutLo;
	
	private ALUOut(){}
	
	private final static ALUOut mInstance = new ALUOut();
	
	public static ALUOut getInstance(){
		return mInstance;
	}

	@Override
	void onClockTick() {
		mALUOutHi = mALUResultHi;
		mALUOutLo = mALUResultLo;
		if (outputDebug && Mode.getDebugLevel() >= Mode.DEBUG_LEVEL_PRINT_ALL) {
			System.out.println("ALUOutLo = " + mALUOutLo);
		}
	}

	@Override
	boolean setData(int keyInterface, int data) {
		if (outputDebug && Mode.getDebugLevel() >= Mode.DEBUG_LEVEL_PRINT_ALL) {
			System.out.println("ALUOut.setData("+keyInterface+", "+data+")");
		}
		switch (keyInterface) {
		case KEY_ALU_RESULT_HI:
			mALUResultHi = data;
			return true;
		case KEY_ALU_RESULT_LO:
			mALUResultLo = data;
			return true;
		}
		return false;
	}

	@Override
	int getData(int keyInterface) {
		switch (keyInterface) {
		case KEY_ALU_OUT_HI:
			return mALUOutHi;
		case KEY_ALU_OUT_LO:
			return mALUOutLo;
		}
		return 0;
	}

}
